#pragma once
#include <memory>
#include <mutex>
#include <vector>
#include "TcpClient.h"

#include "common_opr_all.h"
#include "dat_parser.h"
#include "encode_srv.pb.h"

using namespace std;

class TcpClientInstance
{
public:
    void init(const std::string &fileName_ved, const TriggerEventInfo &trigger, const std::string &fileName_3d);
    
    static TcpClientInstance &getInstance();

    // void socketThread(SocketData &sd,CTcpClient &tcpClient, char *memSendfram, int &memLen);

    // void readFile(const std::string fileName_ved, const TriggerEventInfo trigger, const std::string fileName_3d);

    //xiugai
    void pareOneFrame(const ProtoData &element);
    void sendStart(const std::map<std::string, std::vector<ProtoData>> &pieceData, const TriggerEventInfo &trigger);
    void sendEnd(const TriggerEventInfo &trigger, const std::string &fileName_3d, uint64_t endFrameUtcTime);
private:
    TcpClientInstance();
    ~TcpClientInstance();

    // void dataSubpackage(SocketData &sdh32, SocketData &sdh16, SocketData &sdh8,
    //                                     SocketData &sdh4, SocketData &sdh2, SocketData &sdh1, const TriggerEventInfo &trigger, const std::string fileName3D);

    // void send3DVedioStream(const std::string &fileName3D, CTcpClient &tcpClient, char *memSendfram);

    // long int sendFrameLeft(CTcpClient &tcpClient, const char *memSendfram, int &memLen);
    // long int sendFrame(const std::string &rdata, CTcpClient &tcpClient, char *memSendfram, int &desCurPos);

    void sendOneFrame(const uint8_t &cameraId, const EncodeSrv::EncodeH265 &enc);
    void send3DVedioStream(const std::string &fileName3D);

    int KCpMaxSize = 2*1024*1024; //2M 2*1024*1024

    // CTcpClient *tcpClient = nullptr;
    std::unique_ptr<CTcpClient> tcpClient;  // 使用 unique_ptr 管理内存  
    // std::fstream m_test_file;
    string m_sockeFile;

    long int m_DataLenVedio = 0;//视频数据总共多少
    long int m_SendLenVedio = 0;//视频数据发送成功了多少
    long int m_wrongRes = 0;//错误的分辨率帧数

    map<uint8_t, map<int64_t, uint32_t>> m_stacFrame;//<camid, <framid, size>>


};
